﻿using Roton.Engine;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Roton
{
    public partial class ManagedGame : UserControl, IKeyboard
    {
        /// <summary>
        /// Create a game control that uses the .NET framework only.
        /// </summary>
        public ManagedGame()
        {
            InitializeComponent();
            KeyBuffer = new ZZT32KeyBuffer();
        }

        /// <summary>
        /// Clear the keyboard buffer.
        /// </summary>
        public void ClearKeyboard()
        {
            KeyBuffer.ClearKeyboard();
        }

        /// <summary>
        /// Retrieve the currently pressed key in the buffer.
        /// </summary>
        public Keys GetPressedKey()
        {
            return KeyBuffer.GetPressedKey();
        }

        /// <summary>
        /// Key buffer provided by the Game control.
        /// </summary>
        KeyBuffer KeyBuffer { get; set; }

        /// <summary>
        /// Poll for new keyboard input.
        /// </summary>
        public void PollKeyboard()
        {
            KeyBuffer.PollKeyboard();
        }

        /// <summary>
        /// Hook for control input.
        /// </summary>
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            KeyEventArgs e = new KeyEventArgs(keyData);
            KeyBuffer.Press(e);
            return true;
        }
    }
}
